package sliver.action.shop;

import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import sliver.entity.Goods;
import sliver.service.ShopManager;

import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller("shop.editGoodsAction")
public class EditGoodsAction extends ActionSupport implements RequestAware{

	private static final long serialVersionUID = 2027199736669264831L;
	
	private Integer goodsId;
	
	private Map<String, Object> request;
	
	@Autowired
	private ShopManager shopManager;
	
	public EditGoodsAction(){
		
	}
	
	public Integer getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(Integer goodsId) {
		this.goodsId = goodsId;
	}
	
	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	@Override
	public String execute() throws Exception {
		
		Goods goods = shopManager.detail(goodsId);
		
		if(goods != null){
			request.put("goods", goods);
			return SUCCESS;
		}
		
		return ERROR;
	}
	
}
